unit ParameterInterface;

interface

  uses
    Interface_TLB,
    ComObj,
    ExtActns;

  type
    TParameterInterface = class(TAutoIntfObject, IParameterIntf, IDispatch)
      protected
        function Get_itemCount: Integer; safecall;
        function Items(index: Integer): WideString; safecall;
        property itemCount: Integer read Get_itemCount;
      public
        constructor Create();
        destructor Destroy(); override;
    end;

implementation

  uses
    ActiveX,
    Variants;

  constructor TParameterInterface.Create();
  var
    TypeLib : ITypeLib;
    ExeName : WideString;
  begin
    //Get name of application
    ExeName := ParamStr(0);
    //Load type library from application's resources
    OleCheck(LoadTypeLib(PWideChar(ExeName), TypeLib));
    //Inherit
    inherited Create(TypeLib, IParameterIntf);
  end;

  destructor TParameterInterface.Destroy();
  begin
    inherited;
  end;

  function TParameterInterface.Get_itemCount() : Integer;
  begin
    Result := ParamCount;
  end;

  function TParameterInterface.Items(index: Integer) : Widestring;
  begin
    try
      Result := ParamStr(index);
    except
      Result := VarAsType(Result, varEmpty);
    end;
  end;

end.
